package cn.org.timespace.plat.service.mc.impl;

import java.util.List;

import cn.org.timespace.ons.util.pager.Pager;
import cn.org.timespace.plat.action.mc.PlatMconfModel;
import cn.org.timespace.plat.dao.mc.PlatMcInfoDao;
import cn.org.timespace.plat.dao.mc.PlatMconfDao;
import cn.org.timespace.plat.service.mc.PlatMconfService;
import cn.org.timespace.plat.vo.mc.PlatMcInfo;
import cn.org.timespace.plat.vo.mc.PlatMconf;

public class PlatMconfServiceImpl implements PlatMconfService {
	private PlatMconfDao platMconfDao;
	private PlatMcInfoDao platMcInfoDao;
	
	public PlatMcInfoDao getPlatMcInfoDao() {
		return platMcInfoDao;
	}

	public void setPlatMcInfoDao(PlatMcInfoDao platMcInfoDao) {
		this.platMcInfoDao = platMcInfoDao;
	}

	public PlatMconfDao getPlatMconfDao() {
		return platMconfDao;
	}

	public void setPlatMconfDao(PlatMconfDao platMconfDao) {
		this.platMconfDao = platMconfDao;
	}

	@Override
	public void delete(PlatMconf instance) {
		// TODO Auto-generated method stub
		platMconfDao.delete(instance);
	}

	@Override
	public List<PlatMconf> findByCondition(PlatMconfModel model) {
		// TODO Auto-generated method stub
		return platMconfDao.findByCondition(model);
	}

	@Override
	public List<Object> findByCondition(PlatMconfModel model, Pager p) {
		// TODO Auto-generated method stub
		return platMconfDao.findByCondition(model, p);
	}

	@Override
	public PlatMconf findById(String id) {
		// TODO Auto-generated method stub
		return platMconfDao.findById(id);
	}

	@Override
	public PlatMconf findByMcInfoId(String mcInfoId) {
		// TODO Auto-generated method stub
		return platMconfDao.findByMcInfoId(mcInfoId);
	}

	@Override
	public void save(PlatMconf instance) {
		// TODO Auto-generated method stub
//		platMconfDao.save(instance);
//		PlatMcInfo pli = platMcInfoDao.findById(instance.getMcInfoId());
//		pli.setConf("1");
//		platMcInfoDao.update(pli);
		
		String mcInfoIdd =instance.getMcInfoId();
		String mcInfoIds[] = mcInfoIdd.split(",");
		for(String mi:mcInfoIds){
			PlatMconf pl = instance;
			PlatMconf pt = platMconfDao.findByMcInfoId(mi);
			if(pt != null){
				pl.setTheId(pt.getTheId());
			}
			pl.setMcInfoId(mi);
			platMconfDao.save(pl);
			PlatMcInfo pli = platMcInfoDao.findById(mi);
			pli.setConf("1");
			platMcInfoDao.update(pli);
		}
	}

	@Override
	public void update(PlatMconf instance) {
		// TODO Auto-generated method stub
		platMconfDao.update(instance);
	}
	
	@Override
	public PlatMconf findByMcId(String mcId){
		return platMconfDao.findByMcId(mcId);
	}

}
